-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HW09 is completed #15
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
func ContainsInt(toFind int, searchingString string) bool { | ||
for _, strValue := range strings.Split(searchingString, ",") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
разделение стоит делать на этапе кодогенерации, чтобы валидатор сразу работал с
[]string
и не тратил время на ресурсы -
при желании можно и мапу генерировать, чтобы в целом было O(1). правда N скорее всего мало, так что некритично
} | ||
|
||
func (structName User) Validate() ([]ValidationError, error) { | ||
errors := make([]ValidationError, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var errors []ValidationError
https://github.com/uber-go/guide/blob/master/style.md#nil-is-a-valid-slice
} | ||
|
||
if structName.Age < 18 { | ||
errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в ошибках не хватает ожидаемых и полученных значений
for _, value := range structName.Phones { | ||
|
||
if len(value) != 11 { | ||
errors = append(errors, ValidationError{Field: "Phones", Err: fmt.Errorf("invalid Phones length")}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в ошибке не хватает информации об индексе элемента
errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")}) | ||
} | ||
|
||
if re := regexp.MustCompile("^\\w+@\\w+\\.\\w+$"); re.FindString(string(structName.Email)) == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в продакшн-ready решении скорее всего пришлось бы компилировать регулярочки заранее (в var, например)
сейчас и так приемлимо.
validatedStruct := ValidateStruct(parsedStruct) | ||
document, err := GenerateDocument(validatedStruct) | ||
if err != nil { | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatal?
|
||
go 1.14 | ||
|
||
require github.com/stretchr/testify v1.5.1 | ||
require ( | ||
github.com/fatih/structtag v1.2.0 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
где он используется?
Домашнее задание №9 «Генератор валидаторов»
Критерии оценки
models
- до 2 балловgo-validate
- до 2 балловЗачёт от 7 баллов